package com.sm.healthy.model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.sm.healthy.utils.CacheUtil
import com.sm.healthy.base.App
import com.sm.healthy.data.bean.EcgEntity
import com.sm.healthy.ext.gson
import kotlinx.coroutines.launch
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.util.LogUtils

class EcgMeasurementViewModel : BaseViewModel() {
    val TAG = "UserCenterAddViewModel"
    val ecgValue = StringObservableField("---")
    var startBtn = StringObservableField("开始测量")

    val dao = App.database.ecgDao()
    val ecgEntity = MutableLiveData(EcgEntity(CacheUtil.getCurUid()))

    fun insert() {
        ecgEntity.value?.let {
            LogUtils.debugInfo(TAG, "data = ${gson.toJson(it)}")
            viewModelScope.launch {
                dao.insert(it)
                ecgEntity.postValue(EcgEntity(CacheUtil.getCurUid()))
            }
        }
    }
}